package com.hu.video.service.impl;

import com.hu.video.entity.UserBlockRelations;
import com.hu.video.mapper.UserBlockRelationsMapper;
import com.hu.video.service.IUserBlockRelationsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Objects;
import com.hu.video.entity.dto.UserBlockDTO;

@Service
public class UserBlockRelationsServiceImpl implements IUserBlockRelationsService {
    @Autowired
    private UserBlockRelationsMapper mapper;

    @Override
    public List<UserBlockRelations> getByUserId(Long userId) {
        return mapper.selectByUserId(userId);
    }

    @Override
    public List<UserBlockRelations> getByBlockedUserId(Long blockedUserId) {
        return mapper.selectByBlockedUserId(blockedUserId);
    }

    @Override
    public void addBlock(UserBlockRelations block) {
        int exists = mapper.checkExists(block.getUserId(), block.getBlockedUserId(), block.getBlockType());
        if (exists > 0) {
            throw new RuntimeException("该屏蔽关系已存在");
        }
        mapper.insert(block);
    }

    @Override
    public void removeBlock(UserBlockRelations block) {
        mapper.delete(block);
    }

    @Override
    public List<UserBlockDTO> getUserBlocksWithNames(Long userId) {
        return mapper.selectUserBlocksWithNames(userId);
    }
} 